/*
 *  UI_TitleBar.cpp
 *
 *	Date: 2011-8-23
 *  Author: linshenqi
 */

#include "stdafx.h"
#include "./UI_Frame.h"

extern CDC *g_pDC;
extern CDC g_MemDC;

UI_TitleBar::UI_TitleBar(const CRect *pRect, const GRAPHICPROP *pProp)
	: GraphicBase(pRect, pProp)
{
	m_str[0] = "C";
	m_str[1] = "P";
	m_str[2] = "SERIES";

	m_lf[0].lfCharSet = DEFAULT_CHARSET;
	m_lf[0].lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf[0].lfEscapement = 0;
	strcpy(m_lf[0].lfFaceName, "Times New Roman");
	m_lf[0].lfHeight = 48;
	m_lf[0].lfItalic = true;
	m_lf[0].lfOrientation = 0;
	m_lf[0].lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf[0].lfPitchAndFamily = DEFAULT_PITCH;
	m_lf[0].lfQuality = DEFAULT_QUALITY;
	m_lf[0].lfStrikeOut = false;
	m_lf[0].lfUnderline = false;
	m_lf[0].lfWidth = 0;
	m_lf[0].lfWeight = FW_BOLD;

	m_lf[1].lfCharSet = DEFAULT_CHARSET;
	m_lf[1].lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf[1].lfEscapement = 0;
	strcpy(m_lf[1].lfFaceName, "Times New Roman");
	m_lf[1].lfHeight = 48;
	m_lf[1].lfItalic = true;
	m_lf[1].lfOrientation = 0;
	m_lf[1].lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf[1].lfPitchAndFamily = DEFAULT_PITCH;
	m_lf[1].lfQuality = DEFAULT_QUALITY;
	m_lf[1].lfStrikeOut = false;
	m_lf[1].lfUnderline = false;
	m_lf[1].lfWidth = 0;
	m_lf[1].lfWeight = FW_BOLD;

	m_lf[2].lfCharSet = DEFAULT_CHARSET;
	m_lf[2].lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf[2].lfEscapement = 0;
	strcpy(m_lf[2].lfFaceName, "Times New Roman");
	m_lf[2].lfHeight = 24;
	m_lf[2].lfItalic = true;
	m_lf[2].lfOrientation = 0;
	m_lf[2].lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf[2].lfPitchAndFamily = DEFAULT_PITCH;
	m_lf[2].lfQuality = DEFAULT_QUALITY;
	m_lf[2].lfStrikeOut = false;
	m_lf[2].lfUnderline = false;
	m_lf[2].lfWidth = 0;
	m_lf[2].lfWeight = FW_BOLD;
}

bool UI_TitleBar::OnPaint(CPaintDC *pDC, CDC *pMemDC)
{
	this->DrawBmp(this->m_pRect, &this->m_pBmp, pMemDC, pDC, 0, 0);
	this->m_Menu.OnPaint(pDC, pMemDC);
	this->m_Tab.OnPaint(pDC, pMemDC);

	CRect rc;
	rc.SetRect(this->m_pRect->right - 400, 
			   this->m_pRect->CenterPoint().y - 64 + 10, 
			   this->m_pRect->right, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[0], &rc, m_str[0], COLOR_FORE_MOUSEIN, pDC, pDC);

	rc.SetRect(this->m_pRect->right - 325 - 8, 
			   this->m_pRect->CenterPoint().y - 64 + 10, 
			   this->m_pRect->right - 8, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[1], &rc, m_str[1], RGB(255, 255, 255), pDC, pDC);

	rc.SetRect(this->m_pRect->right - 180 - 24, 
			   this->m_pRect->CenterPoint().y - 14, 
			   this->m_pRect->right - 24, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[2], &rc, m_str[2], RGB(255, 255, 255), pDC, pDC);

	return GraphicBase::OnPaint(pDC, pMemDC);
}

void UI_TitleBar::Redraw()
{
	this->DrawBmp(this->m_pRect, &this->m_pBmp, &g_MemDC, g_pDC, 0, 0);
	this->m_Menu.Redraw();
	this->m_Tab.Redraw();

	CRect rc;
	rc.SetRect(this->m_pRect->right - 400, 
			   this->m_pRect->CenterPoint().y - 64 + 10, 
			   this->m_pRect->right, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[0], &rc, m_str[0], COLOR_FORE_MOUSEIN, g_pDC, g_pDC);

	rc.SetRect(this->m_pRect->right - 325 - 8, 
			   this->m_pRect->CenterPoint().y - 64 + 10, 
			   this->m_pRect->right - 8, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[1], &rc, m_str[1], RGB(255, 255, 255), g_pDC, g_pDC);

	rc.SetRect(this->m_pRect->right - 180 - 24, 
			   this->m_pRect->CenterPoint().y - 14, 
			   this->m_pRect->right - 24, 
			   this->m_pRect->CenterPoint().y);
	this->DrawText(&m_lf[2], &rc, m_str[2], RGB(255, 255, 255), g_pDC, g_pDC);
}

bool UI_TitleBar::OnMouseMove(UINT nFlags, CPoint point)
{
	this->m_Menu.OnMouseMove(nFlags, point);

	return GraphicBase::OnMouseMove(nFlags, point);
}

bool UI_TitleBar::OnLButtonDown(UINT nFlags, CPoint point)
{
	this->m_Menu.OnLButtonDown(nFlags, point);
	this->m_Tab.OnLButtonDown(nFlags, point);

	return GraphicBase::OnLButtonDown(nFlags, point);
}

bool UI_TitleBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	if(!this->m_pRect->PtInRect(point))
		return false;

	return this->m_Tab.OnLButtonDblClk(nFlags, point);
}

void UI_TitleBar::SetRect(const CRect *pRect)
{
	GraphicBase::SetRect(pRect);
	this->SetBmp(BMP_TITLE_BG, this->m_pRect);
	CRect rc;
	rc.SetRect(this->m_pRect->left, this->m_pRect->top, this->m_pRect->left + 512, this->m_pRect->top + 32);
	this->m_Menu.SetRect(&rc);
	rc.SetRect(this->m_pRect->CenterPoint().x - this->m_pRect->Width() / 4, this->m_pRect->bottom - 32, this->m_pRect->CenterPoint().x + this->m_pRect->Width() / 4, this->m_pRect->bottom);
	this->m_Tab.SetRect(&rc);
}

void UI_TitleBar::SetID(int id)
{
	GraphicBase::SetID(id);
	this->m_Menu.SetID(0);
	this->m_Menu.SetParentUI(this);
	this->m_Tab.SetID(1);
	this->m_Tab.SetParentUI(this);
}

void UI_TitleBar::SetBaseWindow(CWnd *pWnd)
{
	GraphicBase::SetBaseWindow(pWnd);
	this->m_Menu.SetBaseWindow(pWnd);
	this->m_Tab.SetBaseWindow(pWnd);
}